package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/2 09:27
 * @apiNote
 */

public class Test00171TitleToNumber {
    public static void main(String[] args) {
        int res = titleToNumber2("ZB");
        System.out.println(res);
    }

    public static int titleToNumber(String columnTitle) {
        int number = 0;
        int multiplier = 1;
        for(int i = columnTitle.length()-1; i >= 0; i--){
            int k = columnTitle.charAt(i) - 'A' + 1;
            number += k * multiplier;
            multiplier *= 26;
        }
        return number;
    }

    public static int titleToNumber2(String columnTitle) {
        int number = 0;
        for(int i = 0; i < columnTitle.length(); i++){
            number = number * 26 +(columnTitle.charAt(i) - 'A' + 1);
        }
        return number;
    }
}
